package mrms.api.web.controllers;

import lombok.AllArgsConstructor;
import mrms.api.entity.UserEntity;
import mrms.api.service.MessageService;
import mrms.api.web.utils.Result;
import org.springframework.web.bind.annotation.*;

/**
 * @author lenchu
 * @date 2019/03/01
 */
@RestController
@AllArgsConstructor
public class MessageController {
    private final MessageService service;

    @GetMapping("/message")
    public Result findAllMessage(@RequestAttribute UserEntity user,
                                 @RequestParam(defaultValue = "1") Integer isRead) {
        return Result.success(service.findAllMessages(user.getId(), isRead));
    }

    @PutMapping("/message/{mid}")
    public Result readMessage(@RequestAttribute UserEntity user,
                              @PathVariable Integer mid) {
        service.readMessage(mid, user.getId());
        return Result.success(null);
    }
}
